﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KPIS.GERP.GBMS.IBLL;
using KPIS.GERP.GBMS.MODEL;
using KPIS.GERP.GBMS.DAL;
using KPIS.GERP.GBMS.DALFactory;

namespace KPIS.GERP.GBMS.BLL
{
    public class StrategyDataMappingBLL : IStrategyDataMappingBLL
    {
        private static readonly IStrategyDataMappingDAL dal = DataAccess.CreateStrategyDataMapping();

        public StrategyDataMappingBLL()
        {

        }

        public void Insert(string code, string name, string descr, int type)
        {
            StrategyDataInfo strategyDataInfo = new StrategyDataInfo(-1, code, name, descr, "", "", SystemInfo._ActiveRecordStatus, "", "", new StrategyTypeInfo(type), new UserRecordInfo(1, null));

            int chkError = dal.Insert(strategyDataInfo);

            if (chkError == 0)
            {
                // Error
            }
        }

        public void Update(int seq, string code, string name, string descr, int type)
        {
            StrategyDataInfo strategyDataInfo = new StrategyDataInfo(seq, code, name, descr, "", "", SystemInfo._ActiveRecordStatus, "", "", new StrategyTypeInfo(type), new UserRecordInfo(null, 1));

            int chkError = dal.Update(strategyDataInfo);

            if (chkError == 0)
            {
                // Error
            }
        }

        public void Delete(int seq)
        {
            int chkError = dal.Delete(seq);
        }

        public IList<StrategyDataMappingInfo> Search(string seq)
        {
            return Search(seq, "", "", "", "", "");
        }

        public IList<StrategyDataMappingInfo> Search(string seq, string type, string list, string parent, string yearstart, string yearend)
        {
            int inSeq = (seq.Length > 0) ? Convert.ToInt32(seq) : 0;
            int inYearStart = (yearstart.Length > 0) ? Convert.ToInt32(yearstart) : 0;
            int inYearEnd = (yearend.Length > 0) ? Convert.ToInt32(yearend) : 0;
            int inType = (type.Length > 0) ? Convert.ToInt32(type) : 0;
            int inList = (list.Length > 0) ? Convert.ToInt32(list) : 0;
            int inParent = (parent.Length > 0) ? Convert.ToInt32(parent) : 0;

            StrategyTypeInfo dataType = new StrategyTypeInfo();
            dataType.Sequence = inType;

            StrategyDataInfo data = new StrategyDataInfo();
            data.Sequence = inList;
            data.StrategyType = dataType;

            StrategyDataMappingInfo strategyDataInfo = new StrategyDataMappingInfo(inSeq, "", null, data, new StrategyDataMappingInfo(inParent), inYearStart, inYearEnd, SystemInfo._ActiveRecordStatus, new UserRecordInfo(100, 100));

            return dal.Search(strategyDataInfo);
        }
    }
}
